<?php
class Dig_Model_Form extends Dig_Form 
{
    protected static $_protectedFields = array(
        'id'		        => 'hidden',
        'meta_date_created'	=> null,
        'meta_date_updated'	=> null,
        'meta_parent_id'	=> null,
    );
    
    public static function factory($model, $build, $populate = true)
    {
        $id = get_class($model);
        if(!empty($model->id)) {
            $id .= '_' . $model->id;
        }
        $form = new self(array('id' => $id));
        
        if(!$build) {
            return $form;
        }
        
        $propertyArray = $model->toArray();
        foreach ($propertyArray as $control => $value) {
            $options['label'] = ucfirst(str_replace('_', ' ', $control));
            if(array_key_exists($control, self::$_protectedFields)) {
                if(null != self::$_protectedFields[$control]) {
                    $form->addElement(self::$_protectedFields[$control], $control);
                }
            } else {
                $form->addElement('text', $control, $options);               
            }
        }
        $form->addElement('submit', 'submit', array('label' => 'Submit'));  
        if($populate){
            $form->populate($propertyArray);
        }
        return $form;
    }
}
?>